package juc.c_020;
/*
   Talk is cheap. Show me the code.
 */

import java.util.concurrent.locks.LockSupport;

/**
 * @Description
 * @Date 2021/6/20
 * @Author liudl
 */
public class T13_LockSupport {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
                if (i == 5) {
                    System.out.println("阻塞" + System.currentTimeMillis());
                    LockSupport.park();
                }
                //                if (i == 7) {
                //                    LockSupport.park();
                //                }
            }
        });
        thread.start();
        //        LockSupport.unpark(thread);
        Thread.sleep(500 * 8);
        System.out.println("放行" + System.currentTimeMillis());
        LockSupport.unpark(thread);
    }
}
